/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky.factory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.List;
import ru.jSky.bridge.major.ArmorBridge;
import ru.jSky.bridge.major.EnchantmentBridge;
import ru.jSky.bridge.major.FormListBridge;
import ru.jSky.bridge.LeveledEntryBridge;
import ru.jSky.bridge.major.LeveledItemListBridge;
import ru.jSky.bridge.major.MajorBridge;
import ru.jSky.bridge.ModBridge;
import ru.jSky.bridge.JSkyBridge;
import ru.jSky.interfaces.Armor;
import ru.jSky.interfaces.JSkyMod;
import ru.jSky.interfaces.Major;
import ru.jSky.bridge.major.KeywordBridge;
import skyproc.ARMO;
import skyproc.ENCH;
import skyproc.FLST;
import skyproc.FormID;
import skyproc.KYWD;
import skyproc.LVLI;
import skyproc.LeveledEntry;
import skyproc.MajorRecord;
import skyproc.Mod;

/**
 *
 * @author Rakev
 */
public class BridgeFactory {

    public <E> Collection<JSkyBridge<E>> createBridges(List<E> records) {
        return createBridges(records, JSkyBridge.class);
    }

    public <E, T extends JSkyBridge<E>> Collection<T> createBridges(Collection<E> records, Class<T> returnedClass) {
        List<T> adapters = new ArrayList<>(records.size());
        for (E record : records) {
            T adapter = createBridge(record, returnedClass);
            adapters.add(adapter);
        }
        return adapters;
    }

    public <E> JSkyBridge<E> createBridge(E record) {
        return createBridge(record, JSkyBridge.class);
    }

    public <E, T extends JSkyBridge<E>> T createBridge(E record, Class<T> returnedClass) {
        if (record instanceof ENCH) {
            return (T) createBridge((ENCH) record);
        }
        if (record instanceof ARMO) {
            return (T) createBridge((ARMO) record);
        }
        if (record instanceof FLST) {
            return (T) createBridge((FLST) record);
        }
        if (record instanceof LVLI) {
            return (T) createBridge((LVLI) record);
        }
        if (record instanceof KYWD) {
            return (T) createBridge((KYWD) record);
        }
        if (record instanceof LeveledEntry) {
            return (T) createBridge((LeveledEntry) record);
        }
        if (record instanceof Mod) {
            return (T) createBridge((Mod) record);
        }
        throw new IllegalArgumentException(""+record.getClass()+" not supported yet.");
    }

    public EnchantmentBridge createBridge(ENCH enchantment) {
        return new EnchantmentBridge(enchantment);
    }

    public ArmorBridge createBridge(ARMO armo) {
        return new ArmorBridge(armo);
    }

    public FormListBridge createBridge(FLST flst) {
        return new FormListBridge(flst);
    }

    public LeveledItemListBridge createBridge(LVLI leveledItemList) {
        return new LeveledItemListBridge(leveledItemList);
    }

    public KeywordBridge createBridge(KYWD keyword) {
        return new KeywordBridge(keyword);
    }

    public LeveledEntryBridge createBridge(LeveledEntry leveledEntry) {
        return new LeveledEntryBridge(leveledEntry);
    }

    public ModBridge createBridge(Mod mod) {
        return new ModBridge(mod);
    }

}
